package com.turing.data.scripts.contract.filter


import com.turing.common.util.FileUtils
import com.turing.common.util.StringUtils
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

class UpperLimitOfInvestmentLeverageRatio_30195_10_filter {

    static List< TaskElementVO.DrawResultVO > doConvert(DependParamsVO dependParams){

        String REGEX = /.*净资产.*/
		String REGEX_1 = /.*资产净值.*/

        def textPathMap = dependParams.textPathMap

        List<TaskElementVO.DrawResultVO > trueValueSet = new ArrayList<>()
        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        if (resultVOs!=null && resultVOs.size()>0) {
            for (int i = 0; i < resultVOs.size(); i++) {
                if(StringUtils.isEmpty(resultVOs.get(i).childTaskSn)){
//                    return  resultVOs
                    continue
                }
                def rawPath = textPathMap.get(resultVOs.get(i).childTaskSn)
                def rawText = FileUtils.loadJson(rawPath)
                def expandOffset = 0
                def start = resultVOs.get(i).start
                def end = resultVOs.get(i).end
                while( expandOffset < 10 && start > expandOffset  ){
                    def expandStr = rawText.substring( start - expandOffset,start )

                    if( expandStr =~ REGEX || expandStr =~ REGEX_1 ){
                        trueValueSet.add( resultVOs.get(i) )
                        return trueValueSet
                    }
                    expandOffset ++
                }
            }
        }

		TaskElementVO.DrawResultVO defaultResultVO = new TaskElementVO.DrawResultVO()
		defaultResultVO.text = ""
		trueValueSet.add( defaultResultVO )
        return  trueValueSet

    }

}
